package edu.gatech.gro.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Calendar;

import android.util.Log;

public class Utils {

	private static final String TAG = "UTILS";

	public static int getCurrentTimestamp() {
		return (int) (Calendar.getInstance().getTimeInMillis() / 1000);
	}

	public static String cleanName(String name) {
		if (name != null) {
			name = name.replaceAll("â|ä|à|Â|Ä|À", "a");
			name = name.replaceAll("ê|ë|é|è|Ê|Ë|É|È", "e");
			name = name.replaceAll("î|ï|Î|Ï", "i");
			name = name.replaceAll("ô|ö|Ô|Ö", "o");
			name = name.replaceAll("û|ü|ù|Û|Ü|Ù", "u");
			name = name.replaceAll("ŷ|ÿ|Ŷ|Ÿ", "y");
			name = name.replaceAll("ç|Ç", "c");
			name = name.replaceAll("'| |&", "-");
			name = name.toLowerCase().trim();
		}
		return name;
	}

	public static String hash(String text) {
		MessageDigest md;
		try {
			md = MessageDigest.getInstance("SHA-256");
			byte[] hash = md.digest(text.getBytes());
			StringBuilder sb = new StringBuilder(64);
			for (byte b : hash) {
				sb.append(String.format("%02x", b));
			}
			return sb.toString();
		} catch (NoSuchAlgorithmException e) {
			Log.e(TAG, e.getMessage());
		}
		return "";
	}
}
